package VscodeTest;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

class Test {
    public static void main(String[] args) {
        testMapArr();
    }

    class User {
        private String name;
        private Integer age;
        private String say;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getAge() {
            return age;
        }

        public void setAge(Integer age) {
            this.age = age;
        }

        public String getSay() {
            return say;
        }

        public void setSay(String say) {
            this.say = say;
        }

        public User(String name, Integer age, String say) {
            this.name = name;
            this.age = age;
            this.say = say;
        }

    }

    private static void testMapArr() {
        Integer[] idsInt = {2000,13000,57000,1000000};

        Map<Integer, User> map = new HashMap<>();
        for(int j = 0; j<2000000;j++) {
            map.put(j, new Test().new User("fisha"+j, j, "say fish hi"+j));
        }
        System.out.println(map.size());

        /*for(Map.Entry<Integer,String> entry:map.entrySet()){
            System.out.println(entry.getKey()+"->"+entry.getValue());
        }*/

        long startTime = System.nanoTime();
        // 第一种
        map.keySet().removeIf( v -> {
            for(int i:idsInt) {
                if(i == v) return true;
            }
            return false;
        });
        // 第二种
        map.keySet().removeIf(v -> new ArrayList<Integer>(Arrays.asList(idsInt)).contains(v));

        //List<String> myList = new ArrayList<String>(Arrays.asList(idsString));
        
        /*Predicate predicate = new Predicate<Integer>() {
            @Override
            public boolean test(Integer v) {
                return Arrays.asList(idsInt).contains(v);
            }
        };
        map.keySet().removeIf(predicate);*/


        
        /*map.keySet().stream().filter(v -> Arrays.asList(idsInt).contains(v)).forEach(System.out::println);*/

        long endTime = System.nanoTime();
        long duration = endTime - startTime;
        System.out.println("use:  " + duration / 1000000);
        System.out.println(map.size());

        /*if(map.containsKey(idsInt[0])) {
            map.remove(idsInt[0]);
        }*/

        /*for(String i : map.values()) {
            System.out.println(i);
        }*/
    }
}